<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        .shadow{
            width: 200px;
            height: 200px;
            background-color: rgba(0,0,0,0.5);
            position: absolute;
            left: 100px;
            top: 100px;
        }
    </style>
</head>
<body>
    <div class="shadow"></div>
</body>
<script>
    // 需求: 鼠标跟随 => 盒子跟着鼠标跑

    // 1. 鼠标先移动盒子再跟随  => 监听鼠标移动和鼠标的位置
    // 2. 盒子跟着鼠标移动      => 盒子怎么跑?  margin  position  translate

    var shadow = document.getElementsByClassName("shadow")[0];

    document.onmousemove = function(e){
        var e = e || window.event;

        var x = e.pageX;
        var y = e.pageY;

        shadow.style.left = x + "px";
        shadow.style.top = y + "px";
    }





</script>
</html>